package com.zanbo.clock.config.web;


import com.zanbo.clock.exception.ServiceException;
import com.zanbo.clock.model.base.bean.ResponseBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: zanbo
 * @description: 全局异常捕获类
 * @date: 上午 11:00 2021-4-26
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    
    /**
     * @author: zanbo
     * @description: 对自定义异常进行捕获并处理返回数据
     * @date: 上午 11:00 2021-4-26
     * @params [request, e]
     * @return com.zanbo.clock.model.base.bean.ResponseBean
     */
    @ExceptionHandler(value = ServiceException.class)
    @ResponseBody
    public ResponseBean serviceExceptionHandler(HttpServletRequest request, ServiceException e) {
        return ResponseBean.error(e.getErrorCode(), e.getErrorMsg(), e.getO());
    }
    
}
